//
//  UITool.m
//  meets-ios
//
//  Created by Mark on 14-7-18.
//  Copyright (c) 2014年 meets. All rights reserved.
//

#import "UITool.h"

@implementation UITool

+ (void)cutIntoCircleImage:(UIImageView *)imageView {
    imageView.layer.cornerRadius = imageView.width/2.f;
    imageView.clipsToBounds = YES;
}

+ (void)cutIntoCircleImage:(UIImageView *)imageView withBorderColor:(UIColor *)color width:(CGFloat)width {
    imageView.layer.cornerRadius = imageView.width/2.f;
    imageView.clipsToBounds = YES;
    imageView.layer.borderWidth = width;
    imageView.layer.borderColor = color.CGColor;
}

+ (UITextField *)buildTextField:(CGRect)frame placeholder:(NSString *)placeholder secure:(BOOL)secure font:(CGFloat)size
{
    UITextField *temp = [[UITextField alloc] initWithFrame:frame];
    [temp setPlaceholder:placeholder];
    [temp setClearButtonMode:UITextFieldViewModeWhileEditing];
    [temp setBorderStyle:UITextBorderStyleNone];
    [temp setAutocorrectionType:UITextAutocorrectionTypeNo];
    [temp setAutocapitalizationType:UITextAutocapitalizationTypeNone];
    [temp setSecureTextEntry:secure];
    [temp setKeyboardType:UIKeyboardTypeEmailAddress];
    temp.font = [UIFont systemFontOfSize:size];
    
    return temp;
}

+ (UIImage *)createImageWithColor:(UIColor *)color {
    CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    
    UIImage *colorImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return colorImage;
}


+ (UIButton *)buttonWithTitle:(NSString *)title
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setBackgroundColor:UIColorFromRGB(0xFF9F58)];
    [btn setTitleColor:UIColorFromRGB(0xFFFFFF) forState:UIControlStateNormal];
    [btn setTitle:title forState:UIControlStateNormal];
    btn.clipsToBounds = YES;
    btn.layer.cornerRadius = 5.0f;
    [btn sizeToFit];
    return btn;
}



@end
